package com.graduation.rescuematerial.common;

import com.graduation.rescuematerial.service.impl.UserServiceImpl;
import com.graduation.rescuematerial.utils.CookieUtil;
import com.graduation.rescuematerial.vo.RespBean;
import com.graduation.rescuematerial.vo.RespBeanEnum;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:CaiShuangLian
 * @FileName:
 * @Date:Created in  2022/4/22 23:54
 * @Version:
 * @Description:校验用户是否登录
 */

public class LoginCheck {

    @Autowired
    private UserServiceImpl userService;

    public RespBean loginCheck(HttpServletRequest request, HttpServletResponse response){
        String ticket= CookieUtil.getCookieValue(request,"userTicket");
        if(ticket!=null && !ticket.isEmpty()){
            return RespBean.success(userService.getUserByCookie(ticket,request,response));
        }
        return RespBean.error(RespBeanEnum.ILLEGAL_OPERATION,"用户未登录");
    }
}
